/*
*
*配置模拟=>模型选择,模型参数设置->时间选择 界面
*/

import React, {Component,PropTypes} from 'react';
import {connect} from 'dva';
import {routerRedux,withRouter } from 'dva/router';
import { Card,Row ,Button ,message} from 'antd';

import {OptimizeModelSelect} from './OptimizationSelect';
import { TimeRangeSelect,DateRangePicker } from '../../../../components/ToolbarItem';
import { optimizationModel,timeRangeList2 } from '../../../../utils/dataConfig';
const ConfigSimulationTb = ({dispatch,configSimulation}) => {
	const tag = 'configSimulation';
	const { 
		optimizeModel,
		CSassets,
		timeRange,
		beginDate,
		endDate,
	} = configSimulation;
	console.log('ConfigSimulation>>>>',configSimulation)
	function onCalculation(){
		const pdtId = []
		CSassets.map((i)=>{
			pdtId.push(i.assetId)
		})
		
		if(timeRange==0&&_.isEmpty(beginDate)&&_.isEmpty(beginDate)){
			message.warning('请选择时间');
		}else if(timeRange!==0&&_.isEmpty(beginDate)&&_.isEmpty(beginDate)){
			dispatch({
				type:"configSimulation/setState",
				payload:{
					isShowTable:true
				}
			})
			// dispatch({
			// 	type:"configSimulation/changeRoute",
			// 	payload:{
			// 		timeRange,
			// 		lPortId:pdtId,
			// 	}
			// })
			dispatch({
				type:"configSimulation/getConfigKpis",
				payload:{
					timeRange,
					lPortId:pdtId,
				}
			})
		}else if(timeRange==0&&!_.isEmpty(beginDate)&&!_.isEmpty(beginDate)){
			dispatch({
				type:"configSimulation/setState",
				payload:{
					isShowTable:true
				}
			})
			// dispatch({
			// 	type:"configSimulation/changeRoute",
			// 	payload:{
			// 		timeRange,
			// 		beginDate,
			// 		endDate,
			// 		lPortId:pdtId,
			// 	}
			// })
			dispatch({
				type:"configSimulation/getConfigKpis",
				payload:{
					timeRange,
					beginDate,
					endDate,
					lPortId:pdtId,
				}
			})
		}

	}
	return(
		<div>
			<Row>
				<OptimizeModelSelect
					value={optimizeModel}
					dispatch={dispatch}
					tag={tag}
					data={optimizationModel}
				/>
			</Row>
			
			<Row>
				<span>时间参数&nbsp;:&nbsp;</span>&nbsp;&nbsp;
				<TimeRangeSelect
					value={timeRange&&timeRangeList2[0].value!=''?timeRangeList2.find(item=>item.value==timeRange).name:''}
					tag='configSimulation'
					dispatch={dispatch}
					data={timeRangeList2}
				/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				{
					timeRange=='0'?<DateRangePicker
							tag='configSimulation'
							dispatch={dispatch}
							beginDate={beginDate}
							endDate={endDate}
						/>:null
				}
				&nbsp;&nbsp;&nbsp;&nbsp;<Button type="primary" onClick={onCalculation}>计算</Button>
			</Row>
		</div>
	)
}

ConfigSimulationTb.propTypes = {}

export default connect(({configSimulation})=>({configSimulation}))(ConfigSimulationTb)